package org.example.business.boostrap;

import lombok.extern.slf4j.Slf4j;
import org.example.business.Events;
import org.example.business.endpoint.ServerOptions;
import org.example.objevent.event.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Slf4j
@Component
public class BootstrapActor {

    @Autowired
    private EventBus bus;

    @Autowired
    private EventBroker broker;

    @Autowired
    private ApplicationContext applicationContext;

    @PostConstruct
    private void bootstrap(){

        setupActor();

        bus.publish(new Event(Events.Startup, new ServerOptions()));

    }

    private void setupActor(){

        applicationContext.getBeansOfType(EventActor.class).forEach((key, value)->{
            broker.register(value);

        });

    }

}
